package MultiChat;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

public class Message {
  
	//private String from;
	private String to;
	private String text;

	Message(BufferedReader in) {
		try {
			String inMessage = (String) in.readLine();
			if (inMessage.startsWith("[")) {
				String[] msg = inMessage.split("]");
				this.to = msg[0].substring(1,msg[0].length());
				this.text = msg[1];
			} else {
				this.to = "all";
				this.text = inMessage;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	Message(String to, String text) {
		this.to = to;
		this.text = text;
	}

	public String getTo() {
		return to;
	}

	public String getText() {
		return text;
	}

	public void sendMessage(PrintWriter out) {
		out.println(this.text);
		out.flush();
	}

	@Override
	public String toString() {
		return text;
	
	}
}
